#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int n,m,fl,x[maxn],y[maxn],num;
int wsum[maxn][2],wcha[maxn][2],lens[2],lenc[2];
map<int, int> mps,mpc;
int nums[2],numc[2];
int main()
{
    freopen("bishop.in","r",stdin);
    freopen("bishop.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    if(n>m) swap(n,m),fl=1;
    if(n==m)
    {
        cout<<2*n-2<<'\n';
        for(int i=1;i<=n;i++)
        {
            cout<<i<<' '<<1<<'\n';
            if(i!=1 || i!=n) cout<<i<<' '<<m<<'\n';
        }
        return 0;
    }
    for(int i=1;i<=n;i++)
    {
        num++;
        x[num]=i,y[num]=1;
        num++;
        x[num]=i,y[num]=m;
    }
    int k=0;
    for(int i=m;i>=n+2;i--)
    {
        k=i%2;
        wsum[++lens[k]][k]=i;
    }
    for(int i=n-m+1;i<=-1;i++)
    {
        k=(i%2+2)%2;
        wcha[++lenc[k]][k]=i;
    }
    for(int i=1;i<=min(lens[0],lenc[0]);i++)
    {
        num++;
        x[num]=(wsum[i][0]+wcha[i][0])/2;
        y[num]=wsum[i][0]-x[num];
    }
    for(int i=1;i<=min(lens[1],lenc[1]);i++)
    {
        num++;
        x[num]=(wsum[i][1]+wcha[i][1])/2;
        y[num]=wsum[i][1]-x[num];
    }
    for(int i=2;i<=n+m;i++) nums[i%2]++;
    for(int i=1-m;i<=n-1;i++) numc[((i%2)+2)%2]++;
    assert(num==min(nums[0],numc[0])+min(nums[1],numc[1]));
    cout<<num<<'\n';
    for(int i=1;i<=num;i++)
    {
        //if(!(x[i]>=1 && y[i]>=1 && x[i]<=n && y[i]<=m))
            //cout<<x[i]<<' '<<y[i]<<' '<<n<<' '<<m<<endl;
        assert(x[i]>=1 && y[i]>=1 && x[i]<=n && y[i]<=m);
        if(fl==1) swap(x[i],y[i]);
        assert(mps[x[i]+y[i]]==0 && mpc[x[i]-y[i]]==0);
        cout<<x[i]<<' '<<y[i]<<'\n';
        mps[x[i]+y[i]]=1,mpc[x[i]-y[i]]=1;
    }
    return 0;
}
